package com.alkalinesolutions.json.core;

/**
 * The object graph supplied for serialization contains at least one Object
 * which, directly or indirectly, points to itself. This would result in JSON
 * text which infinitely recurses, therefore being of infinite length.
 * 
 * An example of serialization which would result in a Cyclical dependency:
 * 
 * <pre>
 * List&lt;Object&gt; root = new ArrayList&lt;Object&gt;();
 * root.add(root);
 * Serializer.serialize(root);
 * </pre>
 * 
 * @author David Waite &lt;<a href='mailto:david@alkaline-solutions.com'>david@alkaline-solutions.com</a>&gt;
 */
public class CyclicalStructureException extends RuntimeException {
	private static final long serialVersionUID = 1L;
	private final Object root;

	public CyclicalStructureException(final Object root) {
		super();
		this.root = root;
	}

	@Override
	public String getMessage() {
		return String.format(Messages
				.getString("CyclicalStructureException.message"), root); //$NON-NLS-1$
	}
}
